package com.atguigu.gmall.cart.controller;

import com.atguigu.gmall.cart.service.CartService;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.cart.CartItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2024/10/5 1:22
 */
@RequestMapping("/api/cart")
@RestController
public class CartController {
    @Autowired
    CartService cartService;
    @GetMapping("/cartList")
    public Result cartList(){
        List<CartItem> cartItemList=cartService.cartList();
        return Result.ok(cartItemList);
    }
    @PostMapping("/addToCart/{skuId}/{num}" )
    public Result updateNumToCart(@PathVariable("skuId") Long skuId,@PathVariable("num") Integer num){
        cartService.updateNumToCart(skuId,num);
        return Result.ok();
    }

    ///checkCart/47/0
    @GetMapping("/checkCart/{skuId}/{checked}")
    public Result updateCheckToCart(@PathVariable("skuId") Long skuId,@PathVariable("checked") Integer checked){
        cartService.updateCheckToCart(skuId,checked);
        return Result.ok();
    }
    ///deleteCart/47
    @DeleteMapping("/deleteCart/{skuId}")
    public Result deleteCartItem(@PathVariable("skuId") Long skuId){
        cartService.deleteCartItem(skuId);
        return Result.ok();
    }
}
